﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIController : MonoBehaviour
{
    public GameObject uiReward, uiFailed;
    public MainUI mainUI;
    public Vector3 JinbiPos;
    public static UIController instance;

    private void Awake()
    {
        instance = this;
    }
    // Use this for initialization
    void Start()
    {
        JinbiPos = Camera.main.ScreenToWorldPoint(transform.Find("MainUI/Right/Image").position);
    }

    public void OpenUIReward()
    {
        StopAllCoroutines();
        StartCoroutine(OpenReward());
    }

    public void OpenUIFailed()
    {
        if (GameController.instance.enemies.Count > 0)
        {
            StopAllCoroutines();
            StartCoroutine(OpenFailed());
        }
    }

    IEnumerator OpenReward()
    {
        yield return new WaitForSeconds(2f);
        uiReward.SetActive(true);
        uiReward.GetComponent<UIReward>().Open();
    }

    IEnumerator OpenFailed()
    {
        yield return new WaitForSeconds(0.75f);
        if (GameController.instance.enemies.Count > 0)
        {
            Time.timeScale = 0;
            uiFailed.SetActive(true);
            uiFailed.GetComponent<UIFailed>().Open();
        }
    }
}